package com.bing.dao;

import com.bing.bean.sys.SysRole;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2015/6/13.
 */
@Repository
public interface SysRoleDao {

    @Insert("insert into SysRole(role,description) values(#{role.value},#{role.description})")
    int createSysRole(SysRole role);


    /**
     * 根据用户ID查找用户对应的角色列表
     *
     * @param id
     * @return
     */
    @Select("select * from SysRole where id in (select roleId from User_Role where userId=#{id})")
    @Results(@Result(property = "sysPermissions", column = "id", many = @Many(select = "com.bing.dao.SysPermissionDao.findPermissionsByRoleId")))
    List<SysRole> findRolesByUserId(int id);
}
